package com.wlcorp.forcazamis.sys.util;
/**
 * 模块名称: 公共类
 * 类 名 称: Random
 * 功能说明: 随机值
 */

import java.util.Random;


public class RandomLetterDigit {
     
   

  /**取得数字与字母组成的随机值
   * @param null
   * @return String strNumRandom
   */
  public static String genLetterDigitRandom(int size) {
    StringBuffer allLetterDigit = new StringBuffer("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") ;
    Random random = new Random() ;

    StringBuffer randomStrBuf = new StringBuffer("") ;
    for( int i=0; i<size; i++) {
      randomStrBuf.append( allLetterDigit.charAt( random.nextInt(allLetterDigit.length()) ) );
    }
    return randomStrBuf.toString() ;
  }
  public static String genLetterRandom(int size) {
      StringBuffer allLetterDigit = new StringBuffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ") ;
      Random random = new Random() ;

      StringBuffer randomStrBuf = new StringBuffer("") ;
      for( int i=0; i<size; i++) {
        randomStrBuf.append( allLetterDigit.charAt( random.nextInt(allLetterDigit.length()) ) );
      }
      return randomStrBuf.toString() ;
    }

  /**取得数字组成的随机值
   * @param null
  */
  public static int DigitRandom(int size) {
        int create_id = 123456789;
        try {
            int numDigit = size;
            double d = Math.random();
            int n = 1;
            for (int i = 0; i < numDigit; i++)
                n = n * 10;
            create_id = (int) (d * n) + 1;
            if (create_id == Integer.MAX_VALUE){
                create_id = DigitRandom(9);
            }
        } catch (Exception e) {
        }
        return create_id;
    }

  public static String genUrlRandom(String urllink) {
    try {
      String temp ;
      if (urllink.indexOf('?') != -1) {
        temp = urllink + "?rand=" + genLetterDigitRandom(16);
      }
      else {
        temp = urllink + "&rand=" + genLetterDigitRandom(16);
      }
      return temp ;
    }
    catch(Exception e) {
      return urllink;
    }
  }
}
